using System.Collections.Generic;

public class PlayerStore : Store
{
    public int lastIndex = -1;
    public Recipe lastRecipe;
    public BreaKing breaKing = new BreaKing();
    int index = 0;
    public ItemStack CursourItem;
    public List<Recipe> recipes = new List<Recipe>();
    public PlayerStore() : base(41)
    {
        Max = 36;
        Items = new ItemStack[Size];
    }
    public void setIndex(int i)
    {
        breaKing.Reset();
        Updata = true;
        if (i > 8) index = 0;
        else if (i < 0) index = 8;
        else index = i;
    }
    public int getIndex()
    {
        return index;
    }
    public void SubCurosrItemAmount(int amount)
    {
        Updata = true;

        if (CursourItem == null) return;
        CursourItem.Amount -= amount;
        if (CursourItem.Amount <= 0)
        {
            CursourItem = null;
        }
        return;
    }
    public void AddCurosrItemAmount(int amount)
    {
        Updata = true;

        if (CursourItem == null) return;
        CursourItem.Amount += amount;
        if (CursourItem.Amount > CursourItem.getMaterial().MaxAmount)
        {
            CursourItem.Amount = CursourItem.getMaterial().MaxAmount;
        }
    }
    public ItemStack GetHandItem()
    {
        return GetItemStack(index);
    }
    public int SubHandItemAmount(int amount)
    {
        return SubAmount(index, amount);
    }

    public void SetCurosrItemAmount(int amount)
    {
        Updata = true;
        if (CursourItem == null) return;

        CursourItem.Amount = amount;
        if (CursourItem.Amount > CursourItem.getMaterial().MaxAmount)
        {
            CursourItem.Amount = CursourItem.getMaterial().MaxAmount;
        }
        else
        if (CursourItem.Amount <= 0)
        {
            CursourItem = null;
        }
    }
    //更新合成列表
    public void UpdataRecipe()
    {
        recipes.Clear();
        for (int i = 0; i < Recipes.recipes.Count; i++)
        {
            if (Recipes.recipes[i].block == null && Recipes.recipes[i].CanCraft(this))
            {
                if (lastRecipe != null &&Recipes.recipes[i]==lastRecipe)
                {

                }else
                recipes.Add(Recipes.recipes[i]);
            }
        }
        // if (lastRecipe != null && lastRecipe.CanCraft(this))
        // {
        //     Recipe temp = recipes[lastIndex];
        //     recipes[lastIndex] = lastRecipe;
        //     recipes.Add(temp);
        // }
    }
    public int GetCraftMax()
    {
        int max = 0;
        ItemStack[] its = new ItemStack[4];
        its[0] = Items[36];
        its[1] = Items[37];
        its[2] = Items[38];
        its[3] = Items[39];
        for (int i = 0; i < 4; i++)
        {
            if (its[i] != null)
            {
                if (its[i].Amount > max)
                {
                    max = its[i].Amount;
                }
            }
        }
        return max;
    }
}